home *** CD-ROM | disk | FTP | other *** search
/ Chip 2005 August (Alt) / CHIP 2005-08.1.iso / program / guvenlik / syslinux-3.07.exe / com32 / lib / libgcc / __udivmoddi4.c < prev    next >
Encoding:
C/C++ Source or Header  |  2004-11-17  |  529 b   |  33 lines

  1. #include <klibc/diverr.h>
  2. #include <stdint.h>
  3.  
  4. uint64_t __udivmoddi4(uint64_t num, uint64_t den, uint64_t *rem_p)
  5. {
  6.   uint64_t quot = 0, qbit = 1;
  7.   
  8.   if ( den == 0 ) {
  9.     __divide_error();
  10.     return 0;            /* If trap returns... */
  11.   }
  12.  
  13.   /* Left-justify denominator and count shift */
  14.   while ( (int64_t)den >= 0 ) {
  15.     den <<= 1;
  16.     qbit <<= 1;
  17.   }
  18.  
  19.   while ( qbit ) {
  20.     if ( den <= num ) {
  21.       num -= den;
  22.       quot += qbit;
  23.     }
  24.     den >>= 1;
  25.     qbit >>= 1;
  26.   }
  27.  
  28.   if ( rem_p )
  29.     *rem_p = num;
  30.  
  31.   return quot;
  32. }
  33.